package com.minimalist.common.feign.fallback.lindi;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationAgreeVO;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplication.LindiTradeApplicationVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationFeignClient;
import com.minimalist.common.feign.config.BaseFallbackFactory;
import com.minimalist.common.response.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

/**
 * 林地交易申请 Feign 客户端降级工厂
 * 使用FallbackFactory可以获取到异常信息，便于问题排查
 *
 * @author minimalist
 */
@Component
public class LindiTradeApplicationFeignClientFallbackFactory extends BaseFallbackFactory<LindiTradeApplicationFeignClient>{
    private static final Logger log = LoggerFactory.getLogger(LindiTradeApplicationFeignClientFallbackFactory.class);


    @Override
    public LindiTradeApplicationFeignClient create(Throwable cause){
        return new LindiTradeApplicationFeignClient(){
            @Override
            public R<?> addTradeApplication(LindiTradeApplicationVO tradeApplicationVO){
                logServiceUnavailable("添加交易申请", tradeApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> deleteTradeApplicationByTradeApplicationId(Long tradeApplicationId){
                logServiceUnavailable("删除交易申请", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> updateTradeApplicationByTradeApplicationId(LindiTradeApplicationVO tradeApplicationVO){
                logServiceUnavailable("更新交易申请", tradeApplicationVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<PageResp<LindiTradeApplicationVO>> getPageTradeApplicationList(LindiTradeApplicationQueryVO queryVO){
                logServiceUnavailable("分页查询交易申请列表", queryVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<LindiTradeApplicationVO> getTradeApplicationByTradeApplicationId(Long tradeApplicationId){
                logServiceUnavailable("获取交易申请详情", tradeApplicationId, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> agreeTradeApplication(LindiTradeApplicationAgreeVO agreeVO){
                logServiceUnavailable("同意交易申请", agreeVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }

            @Override
            public R<?> approveTradeApplication(LindiTradeApplicationAgreeVO agreeVO){
                logServiceUnavailable("审批交易申请", agreeVO, cause);
                return R.fail(HttpStatus.SERVICE_UNAVAILABLE.value(), "服务不可用: " + cause.getMessage());
            }
        };
    }
}
